package com.example.redis.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author void
 * @date 2021/6/3 10:58
 * @desc 定时器消费队列
 */
@Slf4j
@Component
public class TaskConfig {

    @Autowired
    private RedisTemplate fastRedisTemplate;

//    @Scheduled(cron = "* * * * * *")
    public void consumeRedisQueue(){
        log.debug("定时消费redis队列");
        String key = "key_list";
        ListOperations<String, Integer> operations = fastRedisTemplate.opsForList();
        Integer num = operations.leftPop(key);
        if(num!=null){
            log.debug("消费元素:{}", num);
        }
    }
}
